/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * 中序深度迭代遍历（中序递归也可）
 * @param {TreeNode} root
 * @return {number}
 */
var getMinimumDifference = function (root) {
    let minDiff = Infinity,
        stack = [],
        lastNodeVal = Infinity;

    while (stack.length > 0 || root !== null) {
        while (root !== null) {
            stack.push(root)
            root = root.left
        }

        let node = stack.pop()

        minDiff = Math.min(minDiff, Math.abs(lastNodeVal - node.val))
        lastNodeVal = node.val

        root = node.right
    }
    return minDiff
};